<template>
	<view class="goods-page">
		<goods-list @itemClick="goGoodsDeatil" :goods="goods"></goods-list>
		<view class="isOver" v-if="flag">
			--- 到底了，别把拉我了---
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		components: {
			"goods-list": goodsList
		},
		data() {
			return {
				page: 1,
				goods: [],
				flag: false
			};
		},
		onLoad() {
			this.getHotGoods()
		},
		methods: {
			async getHotGoods(callBack) {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=' + this.page
				})
				this.goods = [...this.goods, ...res.data.message]
				callBack && callBack()
			},
			goGoodsDeatil(id){
				uni.navigateTo({
					url:"../good-detail/good-detail?id="+id
				});
			}
		},
		onReachBottom() {
			if (this.goods.length < this.page * 10) return this.flag = true
			this.page++
			this.getHotGoods()
		},
		onPullDownRefresh() {
			this.page=1
			this.goods=[]
			this.flag=false
			setTimeout(()=>{
				this.getHotGoods(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		}
	}
</script>

<style lang="scss">
	.goods-page {
		background-color: #EEEEEE;
	}
</style>
